package com.wenhao.leetcode.medium;

/**
 * 题目：https://leetcode-cn.com/problems/sort-colors/
 * 颜色分类
 * @author Wenhao Tong
 * @create 2021-07-12 0:32
 */
public class LeetCode75 {
    public static void main(String[] args) {
        LeetCode75 leetCode75 = new LeetCode75();
        leetCode75.sortColors(new int[]{2,2,1,0,2,1});
    }
    public void sortColors(int[] nums) {
        int[] count = new int[3];
        for (int i = 0;i < nums.length;i++) {
            count[nums[i]]++;
        }
        int index = 0;
        for (int color = 0;color < 3;color++) {
            for (int i = 0;i < count[color];i++) {
                nums[index++] = color;
            }
        }
    }
}
